﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBLibrary;

public partial class masterPages_spend_SpendTypeOperation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.Request.QueryString["action"]))
        {
            string action = this.Request.QueryString["action"];
            if (action.Equals("a", StringComparison.OrdinalIgnoreCase))
            {
                string newSpendTypename = this.Request.QueryString["name"];
                SpendTypeDetail st = new SpendTypeDetail();
                st.SpendTypeName = newSpendTypename;
                PoseidonDBHelper.UserDB.Insert(st);
            }
        }
    }
    protected void DeleteImageButton_Click(object sender, ImageClickEventArgs e)
    {
        DB db = PoseidonDBHelper.UserDB;
        for (int i = 0; i <= this.LevelGridView.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)LevelGridView.Rows[i].FindControl("DeleteCheckBox");
            if (cbox.Checked)
            {
                int spendTypeId = int.Parse(LevelGridView.DataKeys[i].Value.ToString());
                if (!db.Exist<SpendItemDetail>(new DBParam("SpendTypeId", spendTypeId)))
                {
                    db.Delete<SpendTypeDetail>(new DBParam("SpendTypeId", spendTypeId));
                }
            }
        }
        LevelGridView.DataBind();
    }
}